import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'

Vue.use(Router)

/* Layout */
import Layout from '@/views/home/index'
import newAnswer from '@/views/question/viewQue/doAnswer'



export const functionRoutes= [
    {
        path: 'moudle',
        name: 'moudle',
        component: () => import('@/views/question/moudle'),
        meta: { title: '问卷管理' }
    },
    {
        path: 'createQue',
        name: 'createQue',
        component: () => import('@/views/question/createQue'),
        meta: { title: '新增问卷'}
    },
    {
        path: 'viewQue',
        name: 'viewQue',
        component: () => import('@/views/question/viewQue'),
        meta: { title: '答卷管理' }
    },
    {
        path: 'doAnswer',
        name: 'doAnswer',
        hidden: true,
        component: () => import('@/views/question/viewQue/doAnswer'),
        meta: { title: '回答问题' }
    },
    {
        path: 'count',
        name: 'count',
        hidden: true,
        component: () => import('@/views/question/count'),
        meta: { title: '统计问卷' }
    },

]


export const constantRoutes = [
    {
        path: '/',
        component: Layout,
        redirect: '/home'
    },
    {
        path: '/home',
        component: () => import('@/views/home/index'),
        children: functionRoutes
    },
    {
        path: '/newAnswer',
        name: 'newAnswer',
        hidden: true,
        component: () => import('@/views/question/viewQue/doAnswer'),
        meta: { title: '回答问题' }
    },
    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
]



export function createAllRouter(){
    return constantRoutes.concat(functionRoutes)
}


const createRouter = () =>  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: createAllRouter()
})



const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

export default router
